<%--
  Created by IntelliJ IDEA.
  User: 86181
  Date: 2022/11/8
  Time: 19:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
        <div style="height:60%">
            <span class="control-label">您正在做的业务是：库存管理/入库申请管理/入库申请登记审核</span>
            <table class="table" id="processatshertab" >

            </table>
        </div>
        <form id="processatherform">
        <!--审核入库产品模态框-->
        <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="gridSystemModalLabel" id="processathermodal">
            <div class="modal-dialog modal-lg">
                <div class="modal-content">
                    <div class="modal-header">
                        <input type="radio" name="pdid" value="0" checked>通过
                        <input type="radio" name="pdid" value="1">不通过
                        <input type="button" class="btn btn-default" onclick="processatherstu()" value="确定">
                        <button class="close" data-dismiss="modal">退出</button>
                        <input type="text" name="id" id="gatherids"  class="form-control" readonly style="outline: none; border:none;display: none">
                    </div>
                    <div class="modal-body">
                            <div class="row">
                                <div class="col-md-5 col-md-offset-4"><h2>入库申请登记审核</h2></div>
                            </div>
                            <br>
                            <div class="row">
                                <div class="col-md-6">
                                    <table>
                                        <tr>
                                            <td>申请单编号:</td>
                                            <td><input type="text" id="gatherIdzhdmodal" readonly name="gatherId" class="form-control"  style="outline: none;border:none"></td>
                                        </tr>
                                        <tr>
                                            <td>入库人:</td>
                                            <td><input type="text" id="storerzhdmodal" readonly name="storer" class="form-control" required style="outline: none;border:none;border-bottom:black 1px dashed"></td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="col-md-6">
                                    <table>
                                        <tr>
                                            <td>入库理由:</td>
                                            <td>
                                                <select class="form-control" id="reasonzhdsmodal">
                                                    <option value="R001-1">生产入库</option>
                                                    <option value="R001-2">库存初始</option>
                                                    <option value="R001-3">赠送</option>
                                                    <option value="R001-4">内部借领</option>
                                                    <option value="R001-5">其他借领</option>
                                                </select>
                                            </td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                            <br>
                            <br>
                            <div style="height:40%">
                                <table  class="table" id="addgoodscp1">
                                </table>
                            </div>
                            <div class="row">
                                <div class="col-md-6">
                                    <table id="gatherdetailstable">
                                        <tr>
                                            <td>总件数:</td>
                                            <td><input type="text" name="amountSum"   id="amountSumahtermodal" class="form-control" readonly style="outline: none; border:none;"></td>
                                        </tr>
                                        <tr>
                                            <td>登记人:</td>
                                            <td><input type="text" name="register" id="registerzhdmodal"  class="form-control" required style="outline: none; border:none; border-bottom:black 1px dashed"></td>
                                        </tr>
                                        <tr>
                                            <td>审核人:</td>
                                            <td><input type="text" name="checker" id="checkerzhdmodal" value="${username}"  class="form-control" required style="outline: none; border:none; border-bottom:black 1px dashed"></td>
                                        </tr>
                                    </table>
                                </div>
                                <div class="col-md-6">
                                    <table>
                                        <tr>
                                            <td>总金额:</td>
                                            <td><input type="text" name="costPriceSum" id="costPriceSumzhdmodal"  class="form-control" readonly style="outline: none; border:none;"></td>
                                        </tr>
                                        <tr>
                                            <td>登记时间:</td>
                                            <td><input type="text" name="registerTime"  id="querygathertimesmodal"  readonly style="outline: none; border:none;"></td>
                                        </tr>
                                        <tr>
                                            <td>审核时间:</td>
                                            <td><input type="text" name="checkTime" id="querygathercheckTime"  readonly style="outline: none; border:none;"></td>
                                        </tr>
                                    </table>
                                </div>
                            </div>
                            <br>
                            <div>
                                <div class="form-group">
                                    <label for="updatemessage-textgoodsmodal" class="control-label">备注:</label>
                                    <textarea class="form-control" name="remark" id="updatemessage-textgoodsmodal" style="width:860px;height:200px"></textarea>
                                </div>
                            </div>
                        </div>
                </div>
            </div>
        </div>
        </form>
        <script>

            $(function () {
                $("#processatshertab").bootstrapTable({
                    url:"queryGatherAll.action",
                    method:'get',                      //请求方式（*）
                    contentType: "application/x-www-form-urlencoded", //如果用tomcat就要写这个
                    striped: true,//是否显示隔行变色
                    cache: false,//是否缓存
                    pagination: true,//是否显示分页
                    sortable: true,//是否显示排序
                    sortOrder: "aso",//排序方式
                    sidePagination: "server", //分页方式：client客户端分页，server服务端分页（*）
                    pageNumber: 1,//初始化加载第一页，默认第一页,并记录
                    pageSize: 5,//每页记录数
                    pageList: [5, 10, 15, 20],//可供选择的每页的行数（*）
                    search: false,//是否显示输入框
                    strictSearch: true,
                    showColumns: true,//是否显示所有的列（选择显示的列）
                    showRefresh: true,//是否显示刷新按钮
                    minimumCountColumns: 2,//最少允许的列数
                    clickToSelect: true,//是否启用点击选中行
                    uniqueId: "id",//每一行的唯一标识，一般为主键列
                    showToggle: true,//是否显示详细视图和列表视图的切换按钮
                    cardView: false,//是否显示详细视图
                    detailView: false,//是否显示父子表
                    //获取查询到的参数
                    queryParams:function (params) {
                        var menu={
                            pagesize:params.limit,
                            pageno:(params.offset/params.limit)+1,
                            sort:params.sort,
                            sortOrder:params.sort,
                        }
                        return menu
                    },
                    columns:[
                        {
                            field:"gatherId",
                            title:"申请编号",
                        },
                        {
                            field:"reasonexact",
                            title:"入库理由",
                        },
                        {
                            field:"registerTime",
                            title:"登记时间",
                        },
                        {
                            field:"amountSum",
                            title:"总件数",
                        },
                        {
                            field:"costPriceSum",
                            title:"总金额(元)",
                        },
                        {
                            field:"",
                            title:"审核",
                            formatter:function (value,row,index) {
                                return "<input type='button' value='审核' onclick='processaherByid("+row.id+")' class='btn btn-success'>"
                            }
                        },
                    ]
                })
                $("#addgoodscp1").bootstrapTable({
                    contentType: "application/x-www-form-urlencoded", //如果用tomcat就要写这个
                    striped: true,//是否显示隔行变色
                    cache: false,//是否缓存
                    pagination: false,//是否显示分页
                    sortable: false,//是否显示排序
                    clickToSelect: true,//是否启用点击选中行
                    uniqueId:"id",//每一行的唯一标识，一般为主键列
                    columns:[
                        {
                            field:"productName",
                            title:"产品名称",
                        },
                        {
                            field:"productId",
                            title:"产品编号",
                        },
                        {
                            field:"productDescribe",
                            title:"描述",
                        },
                        {
                            field:"amount",
                            title:"数量",
                        },
                        {
                            field:"amountUnit",
                            title:"单位",
                        },
                        {
                            field:"costPrice",
                            title:"成本单价(元)",
                        },
                        {
                            field:"subtotal",
                            title:"小计",
                        }
                        ]

                    })
            })
            //根据id审核
            function processaherByid(id) {
                $("#processathermodal").modal("show")
                $("#addgoodscp1").bootstrapTable("removeAll")
                var datetimestack;
                //点击获取当前时间
                $.get("queryCellByDate.action",function (data) {
                    datetimestack=data.datetime;
                },"json")
                //获取方法
                $.post("queryGatherById.action",{"id":id},function (data) {
                    //加载入库数据
                    $("#gatherids").val(id)
                    $("#gatherIdzhdmodal").val(data.gatherId)
                    $("#storerzhdmodal").val(data.storer)
                    $("#reasonzhdsmodal").val(data.reason)
                    $("#amountSumahtermodal").val(data.amountSum)
                    $("#registerzhdmodal").val(data.register)
                    $("#costPriceSumzhdmodal").val(data.costPriceSum)
                    $("#querygathercheckTime").val(datetimestack)
                    $("#querygathertimesmodal").val(data.registerTime)
                    $("#updatemessage-textgoodsmodal").val(data.remark)

                    //赋值
                   var gatherDetail=data.gatherDetails;
                        if(gatherDetail==null){
                            return
                        }
                       var arr=[]
                       for(var i=0;i<gatherDetail.length;i++){
                            arr.push(gatherDetail[i])
                       }
                       $("#addgoodscp1").bootstrapTable("append",arr)
                },"json")
            }
            //点击确定提交   通过或者不通过
            function processatherstu() {
                //获取值form的值
                let arrs = $("#processatherform").serializeArray();
                //创建集合
                var gather={};
                $(arrs).each(function (index,item) {
                    gather[item.name]=item.value;
                })
                //获取表格的数据
               var gaherdetails=$("#addgoodscp1").bootstrapTable("getData")
                //将明细表数据存在实体类中同名的属性上
                gather["gatherDetails"]=gaherdetails;
                console.log(gather)
                $.ajax({
                    url:"updateGaherById.action",
                    data:JSON.stringify(gather),
                    contentType:"application/json",
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        alert(data.msg)
                        $("#processathermodal").modal("hide")
                        $("#processatshertab").bootstrapTable("refresh")
                    }
                })
            }
        </script>
</body>
</html>
